package com.sky.config;/**
 * @Package: com.sky.config
 * @ClassName: RedisConfiguration
 * @Author: CY
 * @CreateTime: 2025/7/23 16:04
 * @Description:
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 *@author ChenYong
 *@time 2025/7/2316:04
 */
@Slf4j
@Configuration
public class RedisConfiguration {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {

        log.info("开始创建RedisTemplate对象...");
        // 创建RedisTemplate对象
        RedisTemplate redisTemplate = new RedisTemplate();
        // 设置连接工厂
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置redis key的序列化方式
        redisTemplate.setKeySerializer(new StringRedisSerializer());

        log.info("RedisTemplate对象创建完成...");
        return redisTemplate;
    }
}
